// @Software: serve
// @File : sys_api
// @Author : vince
// @Time : 2021/9/19 11:24
// @Description  请填写文件描述
package fake

import (
	"fmt"
	"gintify/core"
	"gintify/model"
	"gorm.io/gorm"
)

func FakeApis() {
	var apis = []model.SysApi{
		{Name: "base", Title: "基础", Path: "/", Method: "GET", Blueprint: "", Description: "首页"},
		{Name: "base", Title: "基础", Path: "/api/v1/register", Method: "POST", Blueprint: "", Description: "注册"},
		{Name: "base", Title: "基础", Path: "/api/v1/login", Method: "POST", Blueprint: "", Description: "登录"},
		{Name: "base", Title: "基础", Path: "/api/v1/logout", Method: "POST", Blueprint: "", Description: "注销"},
		{Name: "roles", Title: "角色", Path: fmt.Sprintf("/api/v1/%s", "roles"), Method: "POST", Blueprint: "roles", Description: fmt.Sprintf("新建%s", "角色")},
		{Name: "roles", Title: "角色", Path: fmt.Sprintf("/api/v1/%s", "roles"), Method: "GET", Blueprint: "roles", Description: fmt.Sprintf("获取%s列表", "角色")},
		{Name: "roles", Title: "角色", Path: fmt.Sprintf("/api/v1/%s/:id", "roles"), Method: "GET", Blueprint: "roles", Description: fmt.Sprintf("获取%s", "角色")},
		{Name: "roles", Title: "角色", Path: fmt.Sprintf("/api/v1/%s/:id", "roles"), Method: "PUT", Blueprint: "roles", Description: fmt.Sprintf("更新%s", "角色")},
		{Name: "roles", Title: "角色", Path: fmt.Sprintf("/api/v1/%s/:id", "roles"), Method: "PATCH", Blueprint: "roles", Description: fmt.Sprintf("局部更新%s", "角色")},
		{Name: "roles", Title: "角色", Path: fmt.Sprintf("/api/v1/%s/:id", "roles"), Method: "DELETE", Blueprint: "roles", Description: fmt.Sprintf("删除%s", "角色")},
		{Name: "users", Title: "用户", Path: fmt.Sprintf("/api/v1/%s", "users"), Method: "POST", Blueprint: "users", Description: fmt.Sprintf("新建%s", "用户")},
		{Name: "users", Title: "用户", Path: fmt.Sprintf("/api/v1/%s", "users"), Method: "GET", Blueprint: "users", Description: fmt.Sprintf("获取%s列表", "用户")},
		{Name: "users", Title: "用户", Path: fmt.Sprintf("/api/v1/%s/:id", "users"), Method: "GET", Blueprint: "users", Description: fmt.Sprintf("获取%s", "用户")},
		{Name: "users", Title: "用户", Path: fmt.Sprintf("/api/v1/%s/:id", "users"), Method: "PUT", Blueprint: "users", Description: fmt.Sprintf("更新%s", "用户")},
		{Name: "users", Title: "用户", Path: fmt.Sprintf("/api/v1/%s/:id", "users"), Method: "PATCH", Blueprint: "users", Description: fmt.Sprintf("局部更新%s", "用户")},
		{Name: "users", Title: "用户", Path: fmt.Sprintf("/api/v1/%s/:id", "users"), Method: "DELETE", Blueprint: "users", Description: fmt.Sprintf("删除%s", "用户")},
		{Name: "apis", Title: "资源", Path: fmt.Sprintf("/api/v1/%s", "apis"), Method: "POST", Blueprint: "apis", Description: fmt.Sprintf("新建%s", "资源")},
		{Name: "apis", Title: "资源", Path: fmt.Sprintf("/api/v1/%s", "apis"), Method: "GET", Blueprint: "apis", Description: fmt.Sprintf("获取%s列表", "资源")},
		{Name: "apis", Title: "资源", Path: fmt.Sprintf("/api/v1/%s/:id", "apis"), Method: "GET", Blueprint: "apis", Description: fmt.Sprintf("获取%s", "资源")},
		{Name: "apis", Title: "资源", Path: fmt.Sprintf("/api/v1/%s/:id", "apis"), Method: "PUT", Blueprint: "apis", Description: fmt.Sprintf("更新%s", "资源")},
		{Name: "apis", Title: "资源", Path: fmt.Sprintf("/api/v1/%s/:id", "apis"), Method: "PATCH", Blueprint: "apis", Description: fmt.Sprintf("局部更新%s", "资源")},
		{Name: "apis", Title: "资源", Path: fmt.Sprintf("/api/v1/%s/:id", "apis"), Method: "DELETE", Blueprint: "apis", Description: fmt.Sprintf("删除%s", "资源")},
		{Name: "menus", Title: "菜单", Path: fmt.Sprintf("/api/v1/%s", "menus"), Method: "POST", Blueprint: "menus", Description: fmt.Sprintf("新建%s", "菜单")},
		{Name: "menus", Title: "菜单", Path: fmt.Sprintf("/api/v1/%s", "menus"), Method: "GET", Blueprint: "menus", Description: fmt.Sprintf("获取%s列表", "菜单")},
		{Name: "menus", Title: "菜单", Path: fmt.Sprintf("/api/v1/%s/:id", "menus"), Method: "GET", Blueprint: "menus", Description: fmt.Sprintf("获取%s", "菜单")},
		{Name: "menus", Title: "菜单", Path: fmt.Sprintf("/api/v1/%s/:id", "menus"), Method: "PUT", Blueprint: "menus", Description: fmt.Sprintf("更新%s", "菜单")},
		{Name: "menus", Title: "菜单", Path: fmt.Sprintf("/api/v1/%s/:id", "menus"), Method: "PATCH", Blueprint: "menus", Description: fmt.Sprintf("局部更新%s", "菜单")},
		{Name: "menus", Title: "菜单", Path: fmt.Sprintf("/api/v1/%s/:id", "menus"), Method: "DELETE", Blueprint: "menus", Description: fmt.Sprintf("删除%s", "菜单")},

		// Casbin 组
		//{Name: "casbin", Title: "权限", Path: fmt.Sprintf("/api/v1/%s", "casbin"), Method: "POST", Blueprint: "casbin", Description: fmt.Sprintf("新建%s", "权限")},
		//{Name: "casbin", Title: "权限", Path: fmt.Sprintf("/api/v1/%s", "casbin"), Method: "GET", Blueprint: "casbin", Description: fmt.Sprintf("获取%s列表", "权限")},
		//{Name: "casbin", Title: "权限", Path: fmt.Sprintf("/api/v1/%s/:id", "casbin"), Method: "GET", Blueprint: "casbin", Description: fmt.Sprintf("获取%s", "权限")},
		//{Name: "casbin", Title: "权限", Path: fmt.Sprintf("/api/v1/%s/:id", "casbin"), Method: "PUT", Blueprint: "casbin", Description: fmt.Sprintf("更新%s", "权限")},
		//{Name: "casbin", Title: "权限", Path: fmt.Sprintf("/api/v1/%s/:id", "casbin"), Method: "PATCH", Blueprint: "casbin", Description: fmt.Sprintf("局部更新%s", "权限")},
		//{Name: "casbin", Title: "权限", Path: fmt.Sprintf("/api/v1/%s/:id", "casbin"), Method: "DELETE", Blueprint: "casbin", Description: fmt.Sprintf("删除%s", "权限")},
	}

	db := core.DB.Model(&model.SysApi{})
	_ = db.Transaction(func(tx *gorm.DB) error {
		if tx.First(&model.SysApi{}).RowsAffected > 0 {
			core.LG.Errorf("SysApi表不为空")
			return nil
		}
		for _, api := range apis{
			if err := tx.Create(&api).Error; err != nil {
				core.LG.Errorf("创建SysApi失败, %v\n", err)
				return err
			}
		}
		return nil
	})
}
